﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace YXShop.Web.filehandle
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class dealwith_order_info : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string type = context.Request.QueryString["type"];
            int orderId = Convert.ToInt32(context.Request.QueryString["orderId"]);
            string url = YXShop.TemplateAction.Common.UrlStr("default", "","");
            switch (type)
            {
                case "Downline":
                    string bankId = context.Request.QueryString["bankId"];
                    YXShop.BLL.Order.Orders bll = new YXShop.BLL.Order.Orders();
                    bll.Amend(orderId, "Payment", bankId);
                    ChangeHope.WebPage.BasePage.PageRight("订单已提交成功，等待您对该订单付款，谢谢！", url);
                    break;
                case "BalanceOfPayments":
                    string userName = context.Request.QueryString["userName"];
                    string payMoney = context.Request.QueryString["payMoney"];
                    if (!string.IsNullOrEmpty(userName))
                    {
                        YXShop.BLL.Member.MemberAccount mabll = new YXShop.BLL.Member.MemberAccount();
                        YXShop.Model.Member.MemberAccount mamodel = mabll.GetModel(userName);
                        if (mamodel != null)
                        {
                            decimal money = Convert.ToDecimal(mamodel.Capital) - Convert.ToDecimal(payMoney);
                            if (mabll.Amend(mamodel.UID, "Capital", money) > 0)
                            {

                                YXShop.BLL.Order.Orders ordbll = new YXShop.BLL.Order.Orders();
                                if (ordbll.Amend(orderId, "PaymentStatus", "1") > 0)
                                {
                                    YXShop.Model.Order.PrepayMoney preModel = new YXShop.Model.Order.PrepayMoney();
                                    YXShop.BLL.Order.PrepayMoney preBll = new YXShop.BLL.Order.PrepayMoney();
                                    preModel.OrderId = context.Request.QueryString["orderNo"];
                                    preModel.UserName = userName;
                                    preModel.PayoutMoney = Convert.ToDecimal(payMoney);
                                    preModel.Remark = "用户" + userName + "进行支付";
                                    preModel.BosomNote = "System";
                                    preModel.NoteDate = DateTime.Now;
                                    preModel.NoteName = userName;
                                    preBll.Add(preModel);
                                    ChangeHope.WebPage.BasePage.PageRight("支付成功，谢谢！", url);
                                }
                                else
                                {
 
                                }
                            }
                            else
                            {
                                ChangeHope.WebPage.BasePage.PageError("支付失败，请到会员中心再进行支付，谢谢！", url);
                            }
                        }
                        else
                        {
                            ChangeHope.WebPage.BasePage.PageError("支付失败，请到会员中心再进行支付，谢谢！", url);
                        }
                    }
                    else
                    {
                        ChangeHope.WebPage.BasePage.PageError("支付失败，该用户不存在，谢谢！", url);
                    }
                    break;
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
